from django.db import models


from django.db import models


class Maintenance(models.Model):
    maintenance_id = models.IntegerField(primary_key=True, db_comment='养护id')
    maintenance_road_section = models.ForeignKey('RoadCondition', models.DO_NOTHING, db_column='maintenance_road_section', db_comment='养护路段')
    maintenance_road = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='养护路段所属线路（如X284）')
    maintenance_method = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', db_comment='养护方式')
    maintenance_cost = models.DecimalField(max_digits=10, decimal_places=2, db_comment='养护花费（元）')
    maintenance_duration = models.IntegerField(db_comment='养护周期（天）')
    maintenance_approver = models.ForeignKey('Worker', models.DO_NOTHING, db_column='maintenance_approver', db_comment='养护主要负责人，可多填')
    maintenance_approve_time = models.DateTimeField(db_comment='养护时间')

    class Meta:
        db_table = 'maintenance'


class RoadCondition(models.Model):
    road_section_id = models.IntegerField(primary_key=True, db_comment='路段id')
    road_name = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', db_comment='填写路线名称，如：X284')
    road_lane_num = models.IntegerField(db_comment='填写车道数')
    road_surface_type = models.CharField(max_length=20, db_collation='utf8mb4_general_ci', db_comment='填写路段的路面类型')
    road_start_point = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', db_comment='填写路段起点桩号')
    road_end_point = models.CharField(max_length=50, db_comment='填写路段终点桩号')
    road_length = models.DecimalField(max_digits=10, decimal_places=2, db_comment='路段长度，单位：米')
    road_direction = models.CharField(max_length=10, db_collation='utf8mb4_general_ci', db_comment='上行or下行')
    road_admin_level = models.CharField(max_length=20, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='路段的行政等级（如县道、省道等），可不填')
    road_location = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='路段所在地点（乡镇等），可不填')
    road_maintenance_unit = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='路段的管养单位，可不填')
    road_technical_level = models.CharField(max_length=20, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='路段的技术等级（如一级公路、二级公路等），可不填')
    road_pqi = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, db_comment='路段的PQI（路面使用性能指数），范围为0-100，越高表示越好')
    road_pci = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, db_comment='路段的PCI（路面损坏状况指数），范围为0-100，越低表示越好')
    road_rqi = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, db_comment='路段的RQI（路面行驶质量指数），范围为0-100，越高表示越好')
    road_pqi_level = models.CharField(max_length=10, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='PQI四个等级（差，次，中，良）')
    road_pci_level = models.CharField(max_length=10, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='PCI四个等级（差，次，中，良）')
    road_rqi_level = models.CharField(max_length=10, db_collation='utf8mb4_general_ci', blank=True, null=True, db_comment='RQI四个等级（差，次，中，良）')
    road_dr = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, db_comment='道路的DR（损坏率），范围为0-100%，越低表示损坏程度越低')
    road_iri = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, db_comment='道路的IRI（国际粗糙度指数），单位为m/km，越低表示平整度越高')

    class Meta:
        db_table = 'road_condition'


class Worker(models.Model):
    worker_id = models.IntegerField(primary_key=True, db_comment='工人id')
    worker_name = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', db_comment='工人姓名')
    worker_phone = models.CharField(max_length=20, db_collation='utf8mb4_general_ci', db_comment='工人电话')
    worker_password = models.CharField(max_length=50, db_collation='utf8mb4_general_ci', db_comment='工人密码')
    worker_role = models.CharField(max_length=20, db_collation='utf8mb4_general_ci', db_comment='工人的职位')

    class Meta:
        db_table = 'worker'


